package com.atguigu.gulimall.order.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.OrderConfirmVo;
import com.atguigu.gulimall.order.vo.OrderSubmitVo;
import com.atguigu.gulimall.order.vo.SubmitOrderResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
@Slf4j
@RestController
public class WebController {

    @Resource
    private OrderService orderService;

//    @GetMapping("/{page}.html")
//    public String getPage(@PathVariable("page") String page){
//        return page;
//    }

    /**
     * 跳转结算确认页面
     * @param model
     * @return
     */
    @GetMapping("/toTrade")
    public R toTrade(Model model) throws ExecutionException, InterruptedException {
       OrderConfirmVo orderConfirmVo=orderService.toTrade();
       model.addAttribute("data", orderConfirmVo);
       return R.ok().put("data", orderConfirmVo);
    }


    /**
     * 提交订单****
     * @param orderSubmitVo
     * @return
     */
    @PostMapping("/submitOrder")
    public R submitOrder(OrderSubmitVo orderSubmitVo) {
        SubmitOrderResponseVo submitOrderResponseVo=orderService.submitOrder(orderSubmitVo);
        if(submitOrderResponseVo.getCode()==0){
           log.info("提交订单成功：{}",submitOrderResponseVo.getOrder().getId());
        }
        return R.ok().put("data", submitOrderResponseVo);
    }



}
